package com.zy.chapter5

import com.zy.chapter5.InnerClass.Member

import scala.collection.mutable.ArrayBuffer

/**
 * @author: zhaoyi
 * @create: 2020-04-27 21:39
 * @description: ${description}
 **/
class InnerClass {

  /**
   * 每个InnerClass实例都有自己的Inner类
   * @param name
   */
  class Inner(val name: String) {
    val inners = new ArrayBuffer[Inner]()

    override def toString: String = name
  }

  val innerMembers = new ArrayBuffer[Inner]()

  def join(name: String): Inner = {
    val mem = new Inner(name)
    innerMembers.+=(mem)
    mem
  }

  //伴生对象里面的类大家 跟上面的内部类不同
  val innerObjectMembers = new ArrayBuffer[Member]()
  def joinObjectMem(name: String): Member = {
    val mem = new Member(name)
    innerObjectMembers.+=(mem)
    mem
  }


}

object InnerClass{

  //伴生对象里面的类大家 跟上面的内部类不同
  class Member(val name:String){
    val inners = new ArrayBuffer[Member]()
    override def toString: String = name
  }

}
